home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_toolbx.arc / RESORT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-30  |  727 b   |  26 lines

  1. /*  resort.c - resort after last element of array replaced */
  2. /*  uses pointers to actual data elements and compare functions */
  3. #include   "stdio.h"
  4.  
  5. int  resort(pa,na,pcomp)
  6.   char    *pa[] ;  /* array of pointers to elements to be sorted */
  7.   int    na ;            /* number of elements to be sorted */
  8.   int    (*pcomp) () ;        /* pointer to compare function */
  9.   {
  10.      int   i , j ;        /* indeces for loops */
  11.      char  *ptemp ;        /* temporary storage of one pointer */
  12.      /* insert the last element into the sorted array */
  13.     i = na - 1 ;        /* last element */
  14.     ptemp - pa[i] ;
  15.     j = j - 1 ;
  16.     while( (j >= 0) && (*pcomp)(ptemp,pa[j]) < 0 )
  17.        {  pa[j+1] = pa[j] ;
  18.           j = j - 1 ;
  19.        }
  20.     pa[j+1] = ptemp ;
  21.   }
  22.  
  23.  
  24.  
  25.  
  26.